<!DOCTYPE HTML>
<html lang="en" >
    <!-- Start book  -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Array | </title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../md/javascript/date.html" />
    
    
    <link rel="prev" href="../../md/javascript/string.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="4.3.2"
        data-chapter-title="Array"
        data-filepath="md/javascript/array.md"
        data-basepath="../.."
        data-revision="Tue Sep 19 2017 14:58:58 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        Introduction
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="md/HTML5/readme.html">
            
                
                    <a href="../../md/HTML5/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        HTML
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="md/HTML5/20170719HTML.html">
            
                
                    <a href="../../md/HTML5/20170719HTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        什么是HTML
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="md/HTML5/biaoqian.html">
            
                
                    <a href="../../md/HTML5/biaoqian.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        标签
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="md/HTML5/form.html">
            
                
                    <a href="../../md/HTML5/form.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        表单
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="md/HTML5/form-type.html">
            
                
                    <a href="../../md/HTML5/form-type.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        form标签的类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="md/HTML5/20170721HTML.html">
            
                
                    <a href="../../md/HTML5/20170721HTML.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        其他标签的使用
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="md/CSS/readme.html">
            
                
                    <a href="../../md/CSS/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        CSS3
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="md/CSS/20170722CSS.html">
            
                
                    <a href="../../md/CSS/20170722CSS.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        什么是CSS
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="md/CSS/selector.html">
            
                
                    <a href="../../md/CSS/selector.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        选择器
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="md/CSS/selector/tongpei.html">
            
                
                    <a href="../../md/CSS/selector/tongpei.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.1.</b>
                        
                        通配选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="md/CSS/selector/yuansu.html">
            
                
                    <a href="../../md/CSS/selector/yuansu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.2.</b>
                        
                        元素选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="md/CSS/selector/qunzu.html">
            
                
                    <a href="../../md/CSS/selector/qunzu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.3.</b>
                        
                        群组选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.4" data-path="md/CSS/selector/guanxi.html">
            
                
                    <a href="../../md/CSS/selector/guanxi.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.4.</b>
                        
                        关系选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.5" data-path="md/CSS/selector/shuxing.html">
            
                
                    <a href="../../md/CSS/selector/shuxing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.5.</b>
                        
                        属性选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.6" data-path="md/CSS/selector/weilei.html">
            
                
                    <a href="../../md/CSS/selector/weilei.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.6.</b>
                        
                        伪类选择器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2.7" data-path="md/CSS/selector/weiduixiang.html">
            
                
                    <a href="../../md/CSS/selector/weiduixiang.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.7.</b>
                        
                        伪对象选择器
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="md/CSS/style/readme.html">
            
                
                    <a href="../../md/CSS/style/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        常用样式分类
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="md/CSS/style/font.html">
            
                
                    <a href="../../md/CSS/style/font.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.1.</b>
                        
                        字体样式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="md/CSS/style/box.html">
            
                
                    <a href="../../md/CSS/style/box.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.2.</b>
                        
                        盒子模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="md/CSS/style/border.html">
            
                
                    <a href="../../md/CSS/style/border.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.3.</b>
                        
                        边框样式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="md/CSS/style/paragraph.html">
            
                
                    <a href="../../md/CSS/style/paragraph.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.4.</b>
                        
                        段落样式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="md/CSS/style/background.html">
            
                
                    <a href="../../md/CSS/style/background.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.5.</b>
                        
                        背景样式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="md/CSS/style/float.html">
            
                
                    <a href="../../md/CSS/style/float.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.6.</b>
                        
                        浮动
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="md/CSS/style/position.html">
            
                
                    <a href="../../md/CSS/style/position.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.7.</b>
                        
                        定位
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="md/CSS/style/animation.html">
            
                
                    <a href="../../md/CSS/style/animation.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.8.</b>
                        
                        动画及过渡效果
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.9" data-path="md/CSS/style/iconfont.html">
            
                
                    <a href="../../md/CSS/style/iconfont.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.9.</b>
                        
                        外部icon图标库的使用
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.10" data-path="md/CSS/style/sanjiaoxing.html">
            
                
                    <a href="../../md/CSS/style/sanjiaoxing.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.10.</b>
                        
                        利用border画三角形
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.11" data-path="md/CSS/style/xiaojiao.html">
            
                
                    <a href="../../md/CSS/style/xiaojiao.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.11.</b>
                        
                        对话框旁边的小角制作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3.12" data-path="md/CSS/style/flex.html">
            
                
                    <a href="../../md/CSS/style/flex.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.12.</b>
                        
                        弹性盒子
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="md/CSS/idea/readme.html">
            
                
                    <a href="../../md/CSS/idea/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        小技巧
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="md/CSS/idea/caret-color.html">
            
                
                    <a href="../../md/CSS/idea/caret-color.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.1.</b>
                        
                        光标和placeholder颜色
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="md/CSS/idea/background.html">
            
                
                    <a href="../../md/CSS/idea/background.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.2.</b>
                        
                        部分背景透明
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="md/mobile/readme.html">
            
                
                    <a href="../../md/mobile/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        移动端相关
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" >
            
            <span><b>3.1.</b> [媒体特性与Responsive设计]</span>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="md/mobile/viewport.html">
            
                
                    <a href="../../md/mobile/viewport.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        视口
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="md/mobile/responsive.html">
            
                
                    <a href="../../md/mobile/responsive.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        响应式网页
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="md/javascript/readme.html">
            
                
                    <a href="../../md/javascript/readme.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        JavaScript
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="md/javascript/strict.html">
            
                
                    <a href="../../md/javascript/strict.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        JavaScript的严格模式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="md/javascript/value.html">
            
                
                    <a href="../../md/javascript/value.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" >
            
            <span><b>4.3.</b> [对象]</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.3.1" data-path="md/javascript/string.html">
            
                
                    <a href="../../md/javascript/string.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.1.</b>
                        
                        String
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="4.3.2" data-path="md/javascript/array.html">
            
                
                    <a href="../../md/javascript/array.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.2.</b>
                        
                        Array
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3.3" data-path="md/javascript/date.html">
            
                
                    <a href="../../md/javascript/date.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.3.</b>
                        
                        Date
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3.4" data-path="md/javascript/number.html">
            
                
                    <a href="../../md/javascript/number.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.4.</b>
                        
                        Number
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3.5" data-path="md/javascript/math.html">
            
                
                    <a href="../../md/javascript/math.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.5.</b>
                        
                        Math
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="md/javascript/yunsuanfu.html">
            
                
                    <a href="../../md/javascript/yunsuanfu.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        运算符
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="md/javascript/yuju.html">
            
                
                    <a href="../../md/javascript/yuju.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        语句
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="md/javascript/function.html">
            
                
                    <a href="../../md/javascript/function.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="md/javascript/time.html">
            
                
                    <a href="../../md/javascript/time.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.7.</b>
                        
                        定时器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="md/javascript/dom.html">
            
                
                    <a href="../../md/javascript/dom.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.</b>
                        
                        DOM操作
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.8.1" data-path="md/javascript/search.html">
            
                
                    <a href="../../md/javascript/search.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.1.</b>
                        
                        查找
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8.2" data-path="md/javascript/add.html">
            
                
                    <a href="../../md/javascript/add.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.2.</b>
                        
                        增加
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.8.3" data-path="md/javascript/remove.html">
            
                
                    <a href="../../md/javascript/remove.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.8.3.</b>
                        
                        移除
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="md/javascript/HTML-JavaScript.html">
            
                
                    <a href="../../md/javascript/HTML-JavaScript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.9.</b>
                        
                        在HTML中使用JavaScript
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="md/javascript/CSS-javascript.html">
            
                
                    <a href="../../md/javascript/CSS-javascript.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.10.</b>
                        
                        JavaScript控制样式和属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="md/javascript/json.html">
            
                
                    <a href="../../md/javascript/json.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.11.</b>
                        
                        JSON相关
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" ></a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="array">Array</h1>
<h2 id="&#x65B9;&#x6CD5;">&#x65B9;&#x6CD5;</h2>
<h3 id="&#x521B;&#x5EFA;">&#x521B;&#x5EFA;</h3>
<h4 id="&#x76F4;&#x63A5;&#x521B;&#x5EFA;&#x6570;&#x7EC4;">&#x76F4;&#x63A5;&#x521B;&#x5EFA;&#x6570;&#x7EC4;</h4>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>];
</code></pre>
<h4 id="&#x901A;&#x8FC7;&#x6784;&#x9020;&#x51FD;&#x6570;&#x521B;&#x5EFA;">&#x901A;&#x8FC7;&#x6784;&#x9020;&#x51FD;&#x6570;&#x521B;&#x5EFA;</h4>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr1 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(<span class="hljs-number">5</span>);
<span class="hljs-built_in">console</span>.log(arr1.length);
</code></pre>
<h3 id="&#x7D22;&#x5F15;&#x503C;">&#x7D22;&#x5F15;&#x503C;</h3>
<pre><code class="lang-javascript">arr[<span class="hljs-number">3</span>] = <span class="hljs-literal">null</span>;
arr[<span class="hljs-number">100</span>] = <span class="hljs-number">9</span>;
<span class="hljs-built_in">console</span>.log(arr);
</code></pre>
<h3 id="indexof&#x3001;lastindexof">indexOf()&#x3001;lastIndexOf()</h3>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr4 = [<span class="hljs-string">&quot;h&quot;</span>,<span class="hljs-string">&quot;e&quot;</span>,<span class="hljs-string">&quot;l&quot;</span>,<span class="hljs-string">&quot;l&quot;</span>,<span class="hljs-string">&quot;o&quot;</span>,<span class="hljs-string">&quot;!&quot;</span>];
<span class="hljs-built_in">console</span>.log(arr4.indexOf(<span class="hljs-string">&quot;l&quot;</span>),arr4);
<span class="hljs-built_in">console</span>.log(arr4.lastIndexOf(<span class="hljs-string">&quot;l&quot;</span>),arr4);
</code></pre>
<h3 id="concat">concat()</h3>
<p>&#x8FDE;&#x63A5;&#x4E24;&#x4E2A;&#x6216;&#x66F4;&#x591A;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>];
<span class="hljs-keyword">var</span> arr2 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];
<span class="hljs-built_in">console</span>.log(arr.concat(arr2),arr);
<span class="hljs-comment">//[1,2,3,4,5,6,1,2,3]    [1,2,3,4,5,6]</span>
</code></pre>
<h3 id="push">push()</h3>
<p>&#x961F;&#x5C3E;&#x589E;&#x52A0;&#xFF0C;<strong>&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</strong></p>
<pre><code class="lang-javascript">arr.push(<span class="hljs-number">7</span>,<span class="hljs-number">8</span>);
<span class="hljs-built_in">console</span>.log(arr);
<span class="hljs-built_in">console</span>.log(arr+<span class="hljs-string">&quot;&quot;</span>);
</code></pre>
<h3 id="unshift">unshift()</h3>
<p>&#x961F;&#x5934;&#x589E;&#x52A0;&#xFF0C;<strong>&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</strong></p>
<pre><code class="lang-javascript">arr.unshift(-<span class="hljs-number">1</span>,<span class="hljs-number">0</span>);
<span class="hljs-built_in">console</span>.log(arr);
</code></pre>
<h3 id="pop">pop()</h3>
<p>&#x961F;&#x5C3E;&#x5220;&#x9664;&#xFF0C;<strong>&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr4 = [<span class="hljs-string">&quot;h&quot;</span>,<span class="hljs-string">&quot;e&quot;</span>,<span class="hljs-string">&quot;l&quot;</span>,<span class="hljs-string">&quot;l&quot;</span>,<span class="hljs-string">&quot;o&quot;</span>,<span class="hljs-string">&quot;!&quot;</span>];
<span class="hljs-built_in">console</span>.log(arr4.pop(),arr4);
</code></pre>
<h3 id="shift">shift()</h3>
<p>&#x961F;&#x5934;&#x5220;&#x9664;&#xFF0C;<strong>&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//var arr4 = [&quot;h&quot;,&quot;e&quot;,&quot;l&quot;,&quot;l&quot;,&quot;o&quot;,&quot;!&quot;];</span>
<span class="hljs-built_in">console</span>.log(arr4.shift(),arr4);
</code></pre>
<h3 id="splice">splice()</h3>
<p>&#x622A;&#x53D6;&#xFF0C;<strong>&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//splice()    </span>
arr4 = [<span class="hljs-string">&quot;h&quot;</span>,<span class="hljs-string">&quot;e&quot;</span>,<span class="hljs-string">&quot;l&quot;</span>,<span class="hljs-string">&quot;l&quot;</span>,<span class="hljs-string">&quot;o&quot;</span>,<span class="hljs-string">&quot;!&quot;</span>];

<span class="hljs-comment">//splice(start)    &#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x65F6;&#xFF0C;&#x622A;&#x53D6;&#x8BE5;&#x4E0B;&#x6807;&#x4EE5;&#x540E;&#x7684;&#x6240;&#x6709;&#x5143;&#x7D20;&#xFF0C;</span>
<span class="hljs-built_in">console</span>.log(arr4.splice(<span class="hljs-number">1</span>),arr4);

<span class="hljs-comment">//splice(start,deleteCount) &#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x65F6;&#xFF0C;&#x4ECE;&#x4E0B;&#x6807;&#x4E3A;start&#x7684;&#x5F00;&#x59CB;&#x5220;&#x9664;deleteCount&#x4E2A;&#x5143;&#x7D20;</span>
<span class="hljs-built_in">console</span>.log(arr4.splice(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>),arr4);

<span class="hljs-comment">//splice(start, deleteCount, item1, item2, ...) &#x4E09;&#x4E2A;&#x4EE5;&#x4E0A;&#x7684;&#x53C2;&#x6570;&#x65F6;&#xFF0C;&#x4ECE;&#x4E0B;&#x6807;&#x4E3A;start&#x7684;&#x5F00;&#x59CB;&#x5220;&#x9664;deleteCount&#x4E2A;&#x5143;&#x7D20;&#xFF0C;&#x63D2;&#x5165;item1, item2, ...</span>
<span class="hljs-comment">//&#x5982;&#x679C;deleteCount&#x4E3A;0&#xFF0C;&#x5219;&#x8868;&#x793A;&#x4ECE;start&#x63D2;&#x5165;&#x5143;&#x7D20;</span>
<span class="hljs-built_in">console</span>.log(arr4.splice(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-string">&quot;1&quot;</span>,<span class="hljs-string">&quot;2&quot;</span>),arr4);
</code></pre>
<h4 id="includes">includes()</h4>
<p>&#x5224;&#x65AD;&#x5339;&#x914D;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x5426;&#x5B58;&#x5728;&#x6570;&#x7EC4;&#x5185;&#xFF0C;&#x8FD4;&#x56DE;&#x5E03;&#x5C14;&#x503C;</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//arr4 = [&quot;h&quot;,&quot;e&quot;,&quot;l&quot;,&quot;l&quot;,&quot;o&quot;,&quot;!&quot;];</span>
<span class="hljs-built_in">console</span>.log(arr4.includes(<span class="hljs-string">&quot;l&quot;</span>),arr4);
</code></pre>
<h4 id="reverse">reverse()</h4>
<p>&#x98A0;&#x5012;&#x6570;&#x7EC4;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x987A;&#x5E8F;&#xFF0C;<strong>&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr5 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>];
<span class="hljs-built_in">console</span>.log(arr5.reverse(),arr5);
</code></pre>
<h4 id="map">map()</h4>
<p>map() &#x65B9;&#x6CD5;<strong>&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x6570;&#x7EC4;</strong>&#xFF0C;&#x6570;&#x7EC4;&#x4E2D;&#x7684;&#x5143;&#x7D20;&#x4E3A;&#x539F;&#x59CB;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x5904;&#x7406;&#x540E;&#x7684;&#x503C;&#x3002;   </p>
<p>map() &#x65B9;&#x6CD5;&#x6309;&#x7167;&#x539F;&#x59CB;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x987A;&#x5E8F;&#x4F9D;&#x6B21;&#x5904;&#x7406;&#x5143;&#x7D20;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arr = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>];
<span class="hljs-keyword">var</span> map_arr = arr.map(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">a</span>)</span>{
    <span class="hljs-keyword">return</span> a*<span class="hljs-number">2</span>;
});
<span class="hljs-built_in">console</span>.log(map_arr,arr);

<span class="hljs-built_in">console</span>.log(arr.map(<span class="hljs-built_in">Math</span>.sqrt),arr);

<span class="hljs-comment">//&#x4E5F;&#x53EF;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x65B9;&#x5F0F;&#x64CD;&#x4F5C;&#x53C2;&#x6570;</span>

<span class="hljs-comment">//v:&#x5F53;&#x524D;&#x5143;&#x7D20;&#x7684;&#x503C;        </span>
<span class="hljs-comment">//k:&#x5F53;&#x671F;&#x5143;&#x7D20;&#x7684;&#x7D22;&#x5F15;&#x503C;    </span>
<span class="hljs-comment">//Arr:&#x5F53;&#x671F;&#x5143;&#x7D20;&#x5C5E;&#x4E8E;&#x7684;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;</span>
<span class="hljs-keyword">var</span> map2_arr = arr.map(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">v,k,Arr</span>)</span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;v:&quot;</span>+v);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;k:&quot;</span>+k);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;Arr:&quot;</span>+Arr);
    <span class="hljs-keyword">if</span>(v%<span class="hljs-number">2</span>==<span class="hljs-number">1</span>){
        <span class="hljs-keyword">return</span> v;
    }
    <span class="hljs-keyword">else</span>{

    }
})

<span class="hljs-built_in">console</span>.log(map2_arr);
</code></pre>
<h4 id="filter">filter()</h4>
<p>&#x8FC7;&#x6EE4;&#xFF0C;&#x63A5;&#x6536;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#xFF08;&#x65B9;&#x6CD5;&#x8FD4;&#x56DE;&#x7684;&#x662F;&#x5E03;&#x5C14;&#x503C;&#xFF09;&#xFF0C;</p>
<p>&#x9010;&#x4E2A;&#x5224;&#x65AD;&#x6761;&#x4EF6;&#x662F;&#x5426;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#xFF0C;<strong>&#x8FD4;&#x56DE;&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;&#x7684;&#x503C;</strong></p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">filter</span>(<span class="hljs-params">a</span>)</span>{
    <span class="hljs-keyword">return</span> a%<span class="hljs-number">2</span>==<span class="hljs-number">0</span>;
}

<span class="hljs-built_in">console</span>.log(arr.filter(filter),arr);

<span class="hljs-comment">/******************************************/</span>

arr12 = [<span class="hljs-number">0</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>,<span class="hljs-number">7</span>,<span class="hljs-number">8</span>,<span class="hljs-number">9</span>];
<span class="hljs-keyword">var</span> test_arr = arr12.filter(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">a</span>)</span>{
    <span class="hljs-keyword">return</span> a%<span class="hljs-number">2</span>==<span class="hljs-number">1</span>;
});
<span class="hljs-built_in">console</span>.log(test_arr);
</code></pre>
<h4 id="sort">sort()</h4>
<p>sort() &#x65B9;&#x6CD5;&#x7528;&#x4E8E;&#x5BF9;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x6392;&#x5E8F;&#x3002;    </p>
<p>&#x6392;&#x5E8F;&#x987A;&#x5E8F;&#x53EF;&#x4EE5;&#x662F;&#x5B57;&#x6BCD;&#x6216;&#x6570;&#x5B57;&#xFF0C;&#x5E76;&#x6309;&#x5347;&#x5E8F;&#x6216;&#x964D;&#x5E8F;&#x3002;   </p>
<p><strong>&#x9ED8;&#x8BA4;&#x6392;&#x5E8F;&#x987A;&#x5E8F;&#x4E3A;&#x6309;&#x5B57;&#x6BCD;&#x5347;&#x5E8F;</strong>&#x3002;</p>
<p><strong>&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</strong></p>
<pre><code class="lang-javascript">
<span class="hljs-keyword">var</span> arrs = [<span class="hljs-string">&apos;mello&apos;</span>,<span class="hljs-string">&apos;javascript&apos;</span>,<span class="hljs-string">&apos;jbvascript&apos;</span>];

<span class="hljs-comment">//1.&#x6CA1;&#x6709;&#x53C2;&#x6570;&#xFF0C;&#x6BD4;&#x8F83;&#x5143;&#x7D20;&#x7684;&#x4F4D;&#x7684;Unicoded&#x7F16;&#x7801;&#x6765;&#x4ECE;&#x5C0F;&#x5230;&#x5927;&#x6392;&#x5E8F;&#xFF0C;&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</span>

<span class="hljs-built_in">console</span>.log(arrs.sort(),arrs);
<span class="hljs-comment">//&quot;javascript&quot;, &quot;jbvascript&quot;, &quot;mello&quot;    &quot;javascript&quot;, &quot;jbvascript&quot;, &quot;mello&quot;</span>

<span class="hljs-keyword">var</span> arrs1 = [<span class="hljs-number">1</span>,<span class="hljs-number">13</span>,<span class="hljs-number">11</span>,<span class="hljs-number">2</span>,<span class="hljs-number">22</span>];

<span class="hljs-built_in">console</span>.log(arrs1.sort(),arrs1);
<span class="hljs-comment">//1, 11, 13, 2, 22         1, 11, 13, 2, 22</span>



<span class="hljs-comment">//2.&#x6709;&#x53C2;&#x6570;&#xFF0C;&#x6839;&#x636E;&#x8FD4;&#x56DE;&#x503C;&#x51B3;&#x5B9A;&#x987A;&#x5E8F;</span>

<span class="hljs-keyword">var</span> arrs2 = [<span class="hljs-number">1</span>,<span class="hljs-number">13</span>,<span class="hljs-number">11</span>,<span class="hljs-number">2</span>,<span class="hljs-number">22</span>];

<span class="hljs-comment">//&#x4ECE;&#x5C0F;&#x5230;&#x5927;&#x6392;&#x5E8F;</span>
<span class="hljs-keyword">var</span> arrs2_sort = arrs2.sort(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">a,b</span>)</span>{
    <span class="hljs-comment">//&#x5C0F;&#x4E8E;0&#x7684;&#x6570;        &#x539F;&#x6765;&#x987A;&#x5E8F;</span>
    <span class="hljs-comment">//&#x5927;&#x4E8E;0&#x7684;&#x6570;        &#x5012;&#x5E8F;&#xFF0C;&#x6216;&#x4EA4;&#x6362;&#x4F4D;&#x7F6E;</span>
    <span class="hljs-comment">//0</span>
    <span class="hljs-keyword">return</span> a-b;
});

<span class="hljs-built_in">console</span>.log(arrs2_sort,arrs2);
<span class="hljs-comment">//1, 2, 11, 13, 22         1, 2, 11, 13, 22</span>
</code></pre>
<h4 id="tostring">toString()</h4>
<p>&#x8F6C;&#x6362;&#x4E3A;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x542B;&#x9017;&#x53F7;&#xFF0C;&#x4E0D;&#x4F1A;&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arrs1 = [<span class="hljs-number">1</span>,<span class="hljs-number">13</span>,<span class="hljs-number">11</span>,<span class="hljs-number">2</span>,<span class="hljs-number">22</span>];
<span class="hljs-built_in">console</span>.log(arrs1.toString(),arrs1);

<span class="hljs-comment">//1,11,13,2,22    [1, 11, 13, 2, 22]</span>
</code></pre>
<h4 id="join">join()</h4>
<p>&#x4EE5;&#x67D0;&#x4E2A;&#x5B57;&#x7B26;&#x8FDE;&#x63A5;&#x5143;&#x7D20;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x5148;&#x4F7F;&#x7528;toString&#x65B9;&#x6CD5;&#xFF0C;&#x518D;&#x66FF;&#x6362;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> arrs1 = [<span class="hljs-number">1</span>,<span class="hljs-number">13</span>,<span class="hljs-number">11</span>,<span class="hljs-number">2</span>,<span class="hljs-number">22</span>];
<span class="hljs-built_in">console</span>.log(arrs1.join(<span class="hljs-string">&quot; &quot;</span>),arrs1);

<span class="hljs-comment">//1 11 13 2 22        [1, 11, 13, 2, 22]</span>
</code></pre>
<h4 id="foreach">forEach()</h4>
<p><strong>&#x8FD4;&#x56DE;&#x503C;&#x4E3A;undefined</strong></p>
<pre><code class="lang-javascript">arr.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">v,k,arr</span>)</span>{
    <span class="hljs-built_in">console</span>.log(v);
    <span class="hljs-built_in">console</span>.log(k);
    <span class="hljs-built_in">console</span>.log(arr);
})
</code></pre>
<p>&#x5982;&#x679C;&#x6570;&#x7EC4;&#x5728;&#x8FED;&#x4EE3;&#x65F6;&#x88AB;&#x4FEE;&#x6539;&#x4E86;&#xFF0C;&#x5219;&#x5176;&#x4ED6;&#x5143;&#x7D20;&#x4F1A;&#x88AB;&#x8DF3;&#x8FC7;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> words = [<span class="hljs-string">&quot;one&quot;</span>, <span class="hljs-string">&quot;two&quot;</span>, <span class="hljs-string">&quot;three&quot;</span>, <span class="hljs-string">&quot;four&quot;</span>];
words.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">word</span>) </span>{
      <span class="hljs-built_in">console</span>.log(word);
      <span class="hljs-keyword">if</span> (word === <span class="hljs-string">&quot;two&quot;</span>) {
            words.shift();
      }
});
<span class="hljs-comment">// one</span>
<span class="hljs-comment">// two</span>
<span class="hljs-comment">// four</span>
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../md/javascript/string.html" class="navigation navigation-prev " aria-label="Previous page: String"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../md/javascript/date.html" class="navigation navigation-next " aria-label="Next page: Date"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book  -->
</html>
